<template>
	<view class="page">
		<view class="header">
			<view class="headerTitle">
				个人信息
			</view>
			<view class="tips">
				完善您的个人信息，可以有更好的使用体验奥~
			</view>
		</view>
		
		<!-- 需要上传的 -->
		<view class="shangchuan" v-if="isupload == 1">
			<view class="title">身份证
				<text class="biTian">（点击下方上传身份证信息）</text>
			</view>
			<view class="idBox" >
				<view class="idTitle">
					* 为保障账户及资金安全，请确认身份信息的真实有效。
				</view>
			
			
				<view class="idImageBox" style="float: left;margin-left: 52rpx;">
					<view class="">
						<image @click="selectFile()"
							:src="form.cardFrontImage !== '' ? $utils.imagePath(form.cardFrontImage):'../../static/image/front.png'"
							style="width: 288rpx; height: 190rpx;"></image>
						<view class="imageTxt">
							请拍摄并上传身份证人像面
						</view>
					</view>
				</view>
			
			
			
				<view class="idImageBox" style="float: left;margin-left: 52rpx;">
					<view class="" >
						<image @click="selectFile1()"
							:src="form.cardReverseImage !== '' ? $utils.imagePath(form.cardReverseImage) :'../../static/image/back.png'"
							style="width: 288rpx; height: 190rpx;"></image>
						<view class="imageTxt" >
							请拍摄并上传身份证国徽面
						</view>
					</view>
				</view>
			</view>
			<view class="compelet" @click="submit">
				完善信息
			</view>
		</view>
		
		
		
		
		<view class="bushangchuan" v-else>
			<view class="title">身份证
				<!-- <text class="biTian">（点击下方上传身份证信息）</text> -->
			</view>
			<view class="idBox idBoxreverse" >
				<view class="idImageBox" style="float: left;margin-left: 40rpx;">
					<view class="">
						<image @click="yuLan(form.cardFrontImage)"
							:src="form.cardFrontImage !== '' ? $utils.imagePath(form.cardFrontImage):'../../static/image/front.png'"
							style="width: 288rpx; height: 190rpx;"></image>
					</view>
				</view>
				<view class="idImageBox" style="float: left;margin-left: 97rpx;">	
					<view>
						<image @click="yuLan(form.cardReverseImage)" 
							:src="form.cardReverseImage !== '' ? $utils.imagePath(form.cardReverseImage) :'../../static/image/back.png'"
							style="width: 288rpx; height: 190rpx;"></image>
					</view>
			
				</view>
			</view>
		</view>


	
		<view class="list">
			<!-- 			<view class="items" style="justify-content: center;">
				<u-radio-group v-model="userType" width="230rpx" style="margin-left: 50px;" >
					<u-radio :name="0" :disabled="userType == 1">个人</u-radio>
					<u-radio :name="1" :disabled="userType == 0">法人</u-radio>
				</u-radio-group>
			</view> -->
			<view class="items">
				<view class="itemsTxt">
					用户类型
				</view>
				<view class="itemsContent">
					{{userType == 0 ? '个人' : '法人'}}
				</view>
			</view>
			<view class="items">
				<view class="itemsTxt">
					{{userType== 0 ? '用户名称' : '法人名称'}}
				</view>
				<view class="itemsContent">
					{{userinfo.realname||'用户未填写'}}
				</view>
			</view>

			<view class="items" v-if="userType == 1">
				<view class="itemsTxt">
					公司名称
				</view>
				<view class="itemsContent">
					{{userinfo.companyName||'用户未填写'}}
				</view>
			</view>
			<view class="items">
				<view class="itemsTxt">
					电话
				</view>
				<view class="itemsContent">
					{{mobile || ''}}
				</view>
			</view>
			<view class="items">
				<view class="itemsTxt">
					地址
				</view>
				<view class="itemsContent">
					{{userinfo.address}}
				</view>
			</view>
		</view>

		<u-upload style="display: none;" :action="action" @on-uploaded="onUploaded" ref="uUpload" :width="288"
			:height="190" :max-count="1"></u-upload>
		<u-upload style="display: none;" :action="action" @on-uploaded="onUploaded1" ref="uUpload1" :width="288"
			:height="190" :max-count="1"></u-upload>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isupload:1,
				userType: 0,
				form: {
					cardFrontImage: '',
					cardReverseImage: '',
				},
				action: this.$axios.interfaceUrl() + "/upload",
				// 用户的信息
				userinfo: {},
				mobile: '',
			}
		},
		mounted() {
			this.getUser()
		},
		methods: {

			yuLan(path) {
				var imgs = this.$utils.imagePath(path)
				uni.previewImage({
					urls: [imgs]
				})
			},
			// 获取用户信息
			getUser() {
				this.$axios.request(this.$api.getUser, "GET").then((val) => {
					this.userinfo = val.data
					this.userType = val.data.userType
					if (val.data.cardFrontImage != '' || val.data.cardReverseImage != '') {
						this.isupload = 10
						this.form.cardFrontImage = val.data.cardFrontImage
						this.form.cardReverseImage = val.data.cardReverseImage
					}
				
					this.mobile = val.data.mobile.substr(0, 3) + "****" + val.data.mobile.substr(7)
				})
			},
			selectFile() {
				this.$refs.uUpload.selectFile()
			},
			selectFile1() {
				this.$refs.uUpload1.selectFile()
			},
			onUploaded(e) {
				this.form.cardFrontImage = e[0].response.data.src

			},
			onUploaded1(e) {
				this.form.cardReverseImage = e[0].response.data.src
			},
			submit() {
				if (this.form.cardFrontImage == '') {
					this.$msg.toast("请拍摄并上传身份证人像面")
					return
				}
				if(this.form.cardReverseImage == '') {
					this.$msg.toast("请拍摄并上传身份证国徽面")
					return
				}
				this.$axios.request(this.$api.setPersonInfo, "POST", this.form).then((val) => {
					this.$msg.toastCallback("操作成功", (e) => {
						this.getUser()
					})
				})
			},
		}
	}
</script>

<style>
	.page {
		width: 100%;
		background-color: #F0F2F5;
		height: 100vh;
		overflow: auto;
		padding-bottom: 60rpx;
	}

	.header {
		overflow: hidden;
		width: 100%;
		height: 200rpx;
		background-color: #2E6ADF;
		padding: 0 32rpx;
	}

	.headerTitle {
		font-size: 38rpx;
		font-family: "PingFang SC";
		font-weight: 600;
		color: #fff;
		margin-top: 20rpx;
	}

	.tips {
		font-size: 28rpx;
		font-family: "PingFang SC";
		font-weight: 300;
		color: #fff;
		margin: 36rpx 0;
	}

	.list {
		overflow: auto;
		width: 100%;
		margin-top: 16rpx;
		background-color: #fff;
	}

	.items {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 686rpx;
		height: 90rpx;
		margin: 0 auto 0;
		border-bottom: 2rpx solid #eee;
	}

	.items:last-child {
		border: none;
	}

	.itemsTxt {
		font-size: 28rpx;
		font-size: 28rpx;
		font-family: "PingFang SC";
		font-weight: 600;
		line-height: 40rpx;
		color: #333333;
	}

	.itemsContent {
		font-size: 28rpx;
		font-family: "PingFang SC";
		font-weight: 600;
		color: #888;
	}

	.title {
		width: 686;
		height: 80rpx;
		padding: 0 32rpx;
		background-color: #FFFFFF;
		margin: 16rpx auto 0;
		font-size: 32rpx;
		font-family: "PingFang SC";
		font-weight: 600;
		line-height: 80rpx;
		color: #333333;
		opacity: 1;
	}

	.biTian {
		height: 80rpx;
		line-height: 80rpx;
		font-size: 28rpx;
		font-family: "PingFang SC";
		font-weight: 300;
		color: #62656D;
		margin-left: 20rpx;
	}

	.idBox {
		overflow: hidden;
		height: 448rpx;
		background-color: #FFFFFF;
		margin: 16rpx 0;
	}
	.idBoxreverse {
/* 		display: flex;
		justify-content: center; */
		/* height: 248rpx; */
		max-height: 248rpx;
		
		padding: 30rpx 0;
		/* background-color: #2E6ADF; */
	}
	.idTitle {
		height: 28rpx;
		font-size: 26rpx;
		font-family: "PingFang SC";
		font-weight: 300;
		line-height: 28rpx;
		color: #FF2D55;
		opacity: 1;
		margin: 32rpx 32rpx 64rpx;
	}

	.idImageBox {
		width: 288rpx;
		height: 250rpx;
	}

	.imageTxt {
		height: 33rpx;
		font-size: 24rpx;
		font-family: "PingFang SC";
		font-weight: 400;
		line-height: 33rpx;
		color: #707070;
		opacity: 1;
		margin-top: 20rpx;
	}

	.compelet {
		width: 686rpx;
		height: 80rpx;
		background-color: #2E6ADF;
		opacity: 1;
		border-radius: 4rpx;
		font-size: 32rpx;
		font-family: "PingFang SC";
		font-weight: 400;
		line-height: 80rpx;
		margin: 30rpx auto 32rpx;
		text-align: center;
		color: #FFFFFF;
		opacity: 1;
	}
</style>
